package core;

/**
 * @author Robbie Groenewoudt
 * @version 1.1
 * @since 2011-04-11
 */
public class Vector {

	public double x;
	public double y;

	/**
	 * in deze constructor wordt de x en y standaard op 0 gezet
	 */
	/* /// Constructor //////////////////////////////////////// */
	public Vector() {
		x = y = 0.0;
	}

	/**
	 * 
	 * @param dX de x coordinaat 
	 * @param dY de y coordinaat
	 */
	/* /// Constructor //////////////////////////////////////// */
	public Vector(double dX, double dY) {
		x = dX;
		y = dY;
	}

	// Convert vector to a string ...
	/* /// toString //////////////////////////////////////// */
	public String toString() {
		return "Vector(" + x + ", " + y + ")";
	}

	// Compute magnitude of vector ....
	/* /// length //////////////////////////////////////// */
	public double magnitude() {
		return Math.sqrt(x * x + y * y);
	}

	/**
	 * 
	 * @param scaleFactor de factor waarmee je wilt schalen
	 * @return v2 de geschaalde vector
	 */
	/* /// scale //////////////////////////////////////// */
	public Vector scale(double scaleFactor) {
		Vector v2 = new Vector(this.x * scaleFactor, this.y * scaleFactor);
		return v2;
	}

	// Normalize a vectors length....
	/* /// normalize //////////////////////////////////////// */
	public Vector normalize() {
		Vector v2 = new Vector();

		double length = magnitude();
		if (length != 0) {
			v2.x = x / length;
			v2.y = y / length;
		}

		return v2;
	}
}